package com.demo.maintenance.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.demo.maintenance.R;
import com.demo.maintenance.activity.AssignListActivity;
import com.demo.maintenance.activity.AttendanceListActivity;
import com.demo.maintenance.activity.QuizListActivity;
import com.demo.maintenance.activity.StudentListActivity;
import com.demo.maintenance.activity.SummaryListActivity;
import com.demo.maintenance.contant.Global;
import com.demo.maintenance.utils.ActivityManager;
import com.demo.maintenance.utils.AntiShakeUtils;

import java.text.SimpleDateFormat;

/**
 * HOME PAGE
 */
public class HomeFragment extends BaseFragment {

    private Button btn_course;
    private Button btn_assignment;
    private Button btn_quiz;
    private Button btn_attendance;
    private Button btn_day_summary;
    private LinearLayout container_1;

    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(ActivityManager.getTopActivity()).inflate(R.layout.fragment_home, null);
        initView(view);
        return view;
    }

    private void initView(View view) {
        btn_course = view.findViewById(R.id.btn_course);
        btn_assignment = view.findViewById(R.id.btn_assignment);
        btn_quiz = view.findViewById(R.id.btn_quiz);
        btn_attendance = view.findViewById(R.id.btn_attendance);
        btn_day_summary = view.findViewById(R.id.btn_day_summary);
        container_1 = view.findViewById(R.id.container_1);

        btn_course.setOnClickListener(v -> {
            if (AntiShakeUtils.isInvalidClick(v)) {
                return;
            }
            startActivity(new Intent(getActivity(), StudentListActivity.class));
        });

        btn_assignment.setOnClickListener(v -> {
            if (AntiShakeUtils.isInvalidClick(v)) {
                return;
            }
            startActivity(new Intent(getActivity(), AssignListActivity.class));
        });

        btn_quiz.setOnClickListener(v -> {
            if (AntiShakeUtils.isInvalidClick(v)) {
                return;
            }
            startActivity(new Intent(getActivity(), QuizListActivity.class));
        });

        btn_attendance.setOnClickListener(v -> {
            if (AntiShakeUtils.isInvalidClick(v)) {
                return;
            }
            startActivity(new Intent(getActivity(), AttendanceListActivity.class));
        });

        btn_day_summary.setOnClickListener(v -> {
            if (AntiShakeUtils.isInvalidClick(v)) {
                return;
            }
            startActivity(new Intent(getActivity(), SummaryListActivity.class));
        });

        if (!"guardian".equals(Global.userResponse.data.role)){
            container_1.setVisibility(View.VISIBLE);
        }else {
            container_1.setVisibility(View.GONE);
        }
    }

}
